package com.qf.lanzhou.blog.api.dao.Impl;

import com.qf.lanzhou.blog.api.dao.ArticleDetailDao;
import com.qf.lanzhou.blog.api.pojo.entity.Article;
import com.qf.lanzhou.blog.api.util.BeanProcessor;
import com.qf.lanzhou.blog.api.util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @Author Nerly
 * @Date 2020/12/19 10:37
 * @JDK 1.8
 * @Version 1.0
 */
public class ArticleDetailDaoImpl implements ArticleDetailDao {
    private static QueryRunner queryRunner;

    static {
        queryRunner = new QueryRunner(DruidUtil.getDataSource());
    }

    @Override
    public Article getArticleById(Article article) {
        String sql = "SELECT * FROM t_article WHERE article_id=?";
        BeanHandler<Article> beanHandler = BeanProcessor.getBeanHandler(Article.class);
        Article result = null;
        try {
            result = queryRunner.query(sql, beanHandler, article.getArticleId());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}
